import { http } from "@/utils/http";

/** 告警场景响应模型 */
export type AlertSceneResponse = {
  id: number;
  name: string;
  key: string;
  level: number;
  status: number;
  remark?: string;
  // 可能的其他字段
  [key: string]: any;
};

/** 联系人响应模型 */
export type AlertPeopleResponse = {
  id: number;
  name: string;
  phone?: string;
  email?: string;
  wechat?: string;
  remark?: string;
  // 可能的其他字段
  [key: string]: any;
};

/** 设备响应模型 */
export type AppDeviceResponse = {
  id: number;
  deviceKey: string;
  name: string;
  productName: string;
  status: number;
  deptName?: string;
  // 可能的其他字段
  [key: string]: any;
};

/** 设备分组响应模型 */
export type AppDeviceGroupResponse = {
  id: number;
  groupKey: string;
  name: string;
  purpose?: string;
  remark?: string;
  deptId: number;
  // 可能的其他字段
  [key: string]: any;
};

/** 根据联系人ID获取关联的告警场景列表 */
export const getSceneListByPeopleApi = (peopleId: number) => {
  return http.request<Resp<{
    scenes: AlertSceneResponse[];
  }>>("get", "/alert-operate/scene-list-by-people", {
    params: { peopleId }
  });
};

/** 设置联系人关联的告警场景 */
export const setPeopleSceneRelApi = (peopleId: number, sceneIds: number[]) => {
  return http.request<Resp<null>>("post", "/alert-operate/set-people-scene-rel", {
    data: { peopleId, sceneIds }
  });
};

/** 根据设备ID获取关联的告警场景列表 */
export const getSceneListByDeviceApi = (deviceNo: string) => {
  return http.request<Resp<{
    scenes: AlertSceneResponse[];
  }>>("get", "/alert-operate/scene-list-by-device", {
    params: { deviceNo }
  });
};

/** 设置设备关联的告警场景 */
export const setDeviceSceneRelApi = (deviceNo: string, sceneIds: number[]) => {
  return http.request<Resp<null>>("post", "/alert-operate/set-device-scene-rel", {
    data: { deviceNo, sceneIds }
  });
};

/** 根据场景ID获取关联的设备列表 */
export const getDeviceListBySceneApi = (sceneId: number) => {
  return http.request<Resp<{
    devices: AppDeviceResponse[];
  }>>("get", "/alert-operate/device-list-by-scene", {
    params: { sceneId }
  });
};

/** 设置场景关联的设备 */
export const setSceneDeviceRelApi = (sceneId: number, deviceIds: number[]) => {
  return http.request<Resp<null>>("post", "/alert-operate/set-scene-device-rel", {
    data: { sceneId, deviceIds }
  });
};

/** 根据场景ID获取关联的联系人列表 */
export const getPeopleListBySceneApi = (sceneId: number) => {
  return http.request<Resp<{
    people: AlertPeopleResponse[];
  }>>("get", "/alert-operate/people-list-by-scene", {
    params: { sceneId }
  });
};

/** 设置场景关联的联系人 */
export const setScenePeopleRelApi = (sceneId: number, peopleIds: number[]) => {
  return http.request<Resp<null>>("post", "/alert-operate/set-scene-people-rel", {
    data: { sceneId, peopleIds }
  });
};

/** 根据设备分组ID获取关联的告警场景列表 */
export const getSceneListByDeviceGroupApi = (deviceGroupId: number) => {
  return http.request<Resp<{
    scenes: AlertSceneResponse[];
  }>>("get", "/alert-operate/scene-list-by-device-group", {
    params: { deviceGroupId }
  });
};

/** 设置设备分组关联的告警场景 */
export const setDeviceGroupSceneRelApi = (deviceGroupId: number, sceneIds: number[]) => {
  return http.request<Resp<null>>("post", "/alert-operate/set-device-group-scene-rel", {
    data: { deviceGroupId, sceneIds }
  });
};

/** 根据场景ID获取关联的设备分组列表 */
export const getDeviceGroupListBySceneApi = (sceneId: number) => {
  return http.request<Resp<{
    deviceGroups: AppDeviceGroupResponse[];
  }>>("get", "/alert-operate/device-group-list-by-scene", {
    params: { sceneId }
  });
};

/** 设置场景关联的设备分组 */
export const setSceneDeviceGroupRelApi = (sceneId: number, deviceGroupIds: number[]) => {
  return http.request<Resp<null>>("post", "/alert-operate/set-scene-device-group-rel", {
    data: { sceneId, deviceGroupIds }
  });
};
